#pragma once

#include <string>
#include <vector>

std::string sum_strings( const std::string & a, const std::string & b ) {
    std::vector<char> sum;
    const std::string &shorter = a.size() > b.size() ? b : a, &longer = a.size() > b.size() ? a : b;
    auto itShorter = shorter.rbegin(), itLonger = longer.rbegin();
    bool moreThanNine = false;
    auto addToSum = [&]( char value ) {
        value += moreThanNine;
        moreThanNine = value > 9;
        sum.push_back( value + '0' - 10 * moreThanNine );
    };
    for ( ; itShorter != shorter.rend(); ++itShorter, ++itLonger )
    { addToSum( *itShorter + *itLonger - 2 * '0' ); }
    for ( ; itLonger != longer.rend(); ++itLonger )
    { addToSum( *itLonger - '0' ); }
    if ( moreThanNine )
        sum.push_back( '1' );
    return std::string( sum.rbegin(), sum.rend() );
}
